<template>
	<view class="pageBox">
		<image class="topBG" src="@/static/common/parkCouponBG1.png" mode="scaleToFill"></image>
		<u--form labelPosition="left" :model="formData" :rules="rules" ref="uForm" labelWidth="160rpx"
			labelAlign="center">
			<u-form-item borderBottom prop="plateNo">
				<view class="carNumberBox">
					<car-number-input @numberInputResult="numberInputResult"
						:defaultStr="defaultNum"></car-number-input>
				</view>
			</u-form-item>
			<u-form-item label="手机号" prop="telephone" borderBottom>
				<u--input v-model="formData.telephone" border="none" placeholder="请输入手机号"></u--input>
			</u-form-item>
		</u--form>
		<view class="btnBox">
			<view class="btn" @click="submit">领取</view>
		</view>
	</view>
</template>

<script>
	import * as volumeUserInfoApi from "@/api/volumeUserInfo.js"
	export default {
		data() {
			return {
				defaultNum: '浙',
				formData: {
					plateNo: "",
					telephone: "",
					volumeId: '',
				},
				rules: {
					plateNo: [{
							required: true,
							message: '请输入车牌号',
							trigger: ['change', 'blur'],
						},
						{
							// 自定义验证函数，见上说明
							validator: (rule, value, callback) => {
								// 上面有说，返回true表示校验通过，返回false表示不通过
								// uni.$u.test.mobile()就是返回true或者false的
								return uni.$u.test.carNo(value);
							},
							message: '车牌号不正确',
							// 触发器可以同时用blur和change
							trigger: ['change', 'blur'],
						}
					],
					// 字段名称
					telephone: [{
							required: true,
							message: '请输入手机号',
							trigger: ['change', 'blur'],
						},
						{
							// 自定义验证函数，见上说明
							validator: (rule, value, callback) => {
								// 上面有说，返回true表示校验通过，返回false表示不通过
								// uni.$u.test.mobile()就是返回true或者false的
								return uni.$u.test.mobile(value);
							},
							message: '手机号码不正确',
							// 触发器可以同时用blur和change
							trigger: ['change', 'blur'],
						}
					]
				}

			};
		},
		onLoad(options) {
			this.formData.volumeId = options.id
		},
		methods: {
			numberInputResult(carNo) {
				// console.log('结果--' + carNo)
				this.formData.plateNo = carNo
			},
			submit() {
				const that = this
				this.$refs.uForm.validate().then(res => {
					uni.$u.throttle(
						volumeUserInfoApi.receiveCat(this.formData).then(res => {
							that.$toast1("领取成功", setTimeout(() => {
								that.$back(-1)
							}, 600))
						}), 500)
				}).catch(errors => {})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.pageBox {
		.carNumberBox {
			width: 100%;
			margin-top: 80rpx;
		}

		.topBG {
			width: 100%;
			height: 298rpx;
			object-fit: cover;
		}

		.btnBox {
			padding: 0 128rpx;
			margin-top: 10vh;

			.btn {
				display: flex;
				align-items: center;
				justify-content: center;
				height: 88rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #FFFFFF;
				background: linear-gradient(90deg, #5F96E8 0%, #1977E1 100%);
				border-radius: 40rpx;
			}
		}
	}
</style>